package com.tjh.springbootapi.handles;

import com.tjh.springbootapi.webSocket.ChannelSupervise;
import io.netty.channel.Channel;

import java.util.List;
import java.util.Objects;

/**
 * Create by koala on 2022-09-05
 */
public class WebSocketHandle implements Runnable {

    private String info;

    public WebSocketHandle(String info) {
        this.info = info;
    }

    @Override
    public void run() {
        List<Channel> group = ChannelSupervise.multiBusinessChannelMap.get("/ws/api/helmet/realTimeData");
        if (Objects.isNull(group)) {
            System.out.println("未找到有效的websocket通道");
            return;
        }

        if (Objects.nonNull(info)) {
            //向前端推送数据
            ChannelSupervise.send2Channels(group, info);
        }
    }
}